//
//  LBToneMapFilter.mm
//  OpenGLGame
//
//  Created by Nguyen Cong Huy on 4/5/13.
//  Copyright (c) 2013 UIT. All rights reserved.
//

#include "LBToneMapFilter.h"
#include "LBUtils.h"
#include "LBTexture.h"

char toneMapFragShaderStr[] = ""

"precision mediump float;"

"varying vec2 vtexCoor;"
"varying vec2 vtexCoor2;"

"uniform sampler2D texture;"
"uniform sampler2D texture2; "

"void main()"
"{"
"    lowp vec4 textureColor = texture2D(texture, vtexCoor);"
"    lowp float redCurve = texture2D(texture2, vec2(textureColor.r, 0.0)).r;"
"    lowp float greenCurve = texture2D(texture2, vec2(textureColor.g, 0.0)).g;"
"    lowp float blueCurve = texture2D(texture2, vec2(textureColor.b, 0.0)).b;"
"    gl_FragColor = vec4(redCurve, greenCurve, blueCurve, textureColor.a);"
"}";

LBToneMapFilter::LBToneMapFilter(){
    init(0, toneMapFragShaderStr);
}

void LBToneMapFilter::setToneData(const unsigned char* toneData){
    texture2 = new LBTexture(toneData, 256, 1);
}

LBToneMapFilter::~LBToneMapFilter(){
    DELETE_SAFELY(texture2);
}